package com.stlm2.controller;

import com.stlm2.dems.service.GoodSpecificationService;

import com.stlm2.dems.entity.Specification;
import com.stlm2.dems.service.SpecificationService;
import com.stlm2.dems.service.SpecificationContentService;
import com.stlm2.util.codecontent.CodeContent;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Author：fuchunyu
 * Date：2017/9/8
 * Description：规格控制器
 */
@Controller
@RequestMapping("/specificationC")
public class SpecificationController {

    @Resource
    private SpecificationService specificationService;
    @Resource
    private SpecificationContentService specificationContentService;

    @ResponseBody
    @RequestMapping(value = "/getSpecification.json",produces="application/json;charset=UTF-8")
    public String getSpecification(String companyCode,Integer goodid){

        List<Specification> specification=specificationService.getByGoodId(goodid);

        if(specification.size()>0){
            List<ModelMap> specifications=specificationService.convent(specification);
            for(ModelMap map:specifications){
               String id= map.get("id").toString();
                map.put("data",specificationContentService.convent(specificationContentService.getSpecificationContent(goodid,Integer.parseInt(id))));
            }
            return CodeContent.returnSuccess(specifications);
        }else {
            return CodeContent.returnSuccess(null);
        }
    }
}
